# No2. 52m
def is_want_num(num, n):
    sum = 0
    num_str = str(num)

    for c in num_str:
        sum += int(c) ** n

    return sum == num

def main():
    # 获取输入
    n = int(input())
    m = int(input())

    # 不合法检查
    if n < 3 or n > 7 or m < 0:
        print("-1")
        return

    # 上下边界
    left = 10 ** (n - 1)
    right = 10 ** n

    want_list = []

    for i in range(left, right):
        if is_want_num(i, n):
            want_list.append(i)

    len_w = len(want_list)
    if len_w == 0:
        print("-1")
        return

    print(want_list[m] if m < len_w else want_list[-1]*m)
    
if __name__ == "__main__":
    main()